package com.xd.dubbo.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xd.dubbo.entity.OrderEntity;
import com.xd.dubbo.entity.UserEntity;
import com.xd.dubbo.globalTransaction.annotation.GlobalTransactional;
import com.xd.dubbo.mapper.orderDB.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Component
public class DubboUserConsumer {

    @Reference(check = false)
    UserService userService;

    @Autowired
    OrderMapper orderMapper;

    public boolean login(String account,String pwd){
        return userService.login(account, pwd);
    }

    @GlobalTransactional(startTransactional = true)
    @Transactional(transactionManager = "orderTransactionManager")
    public Integer insert(UserEntity userEntity) throws Exception {

        userService.insert(userEntity);

        int i = 1/0;
        OrderEntity orderEntity = new OrderEntity("consumer", new Date());

        orderMapper.insert(orderEntity);
//                int i = 1/0;

        return 200;
//        return 1;
    }

}
